﻿using System.Collections.Generic;
using EditoneLib.Streams;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Runtime.Serialization;

namespace EditoneLib
{
    public class Project : ObservableCollection<ITrack>
    {
        private readonly Settings _settings;
        private string _name;

        public Project()
            : base()
        {
            _settings = new Settings();
        }

        public string Name
        {
            get { return _name; }
            set
            {
                _name = value;
                OnPropertyChanged(new PropertyChangedEventArgs("Name"));
            }
        }

        public Settings Settings
        {
            get { return _settings; }
        }

        internal IList<ITrack> Tracks
        {
            get { return this.ToList(); }
        }

        public ProjectStream CreateStream()
        {
            var mapping = new ChannelMapping();
            foreach (var track in this)
            {
                var audioTrack = track as IAudioTrack;
                if (audioTrack != null)
                {
                    audioTrack.MapDefault(mapping);
                }
            }

            return CreateStream(mapping);
        }

        public ProjectStream CreateStream(ChannelMapping mapping)
        {
            return new ProjectStream(this, mapping);
        }
    }
}